window.onload=function(){ WindowHeight(0); }


// 检测表单
function CheckForm(){
	if ($id("theme").value == ""){ alert("用户组名称不能为空");$id("theme").focus();return false; }
}



/* *** 权限设置 *** */
function OnclickUG(dataID){
	document.location.href = "memberGroup.php?mudi=setRight&dataID="+ dataID;
}

//隐藏、显示菜单(ImgType:1.上下连接图；2.上连接图)
function TurnMenu(IDname,ImgType){
	if ($id(IDname).style.display == ""){
		$id(IDname).style.display = "none"
		if (ImgType == "2"){
			$id(IDname + "Img").src = "images/userRight/dz2_1.gif";
		}else{
			$id(IDname + "Img").src = "images/userRight/dz1_1.gif";
		}
	}else{
		$id(IDname).style.display = ""
		if (ImgType == "2"){
			$id(IDname + "Img").src = "images/userRight/dz2_2.gif";
		}else{
			$id(IDname + "Img").src = "images/userRight/dz1_2.gif";
		}
	}
	WindowHeight(0);
}

//全选、不选
function CheckBoxAll(str){
	if ($id("allRight").checked){
		if ($id('userRightStr').value != "admin"){
			for (var i=0;i<ULform.elements.length;i++){
				if (ULform.elements[i].value!="用户管理" && ULform.elements[i].value!="用户组维护" && ULform.elements[i].value!="用户维护" && ULform.elements[i].value!="权限设置"){
					ULform.elements[i].checked = true;
				}
			};
		}else{
			for (var i=0;i<ULform.elements.length;i++){ ULform.elements[i].checked = true; };
		}
	}else{
		for (var i=0;i<ULform.elements.length;i++){ ULform.elements[i].checked = false; };
	}
}

//复选框互动
function OnclickCheckBox(IDname,num){
	if ($name(IDname)[num].checked == true){ CKD=true; }else{ CKD=false; }

	for (i=0; i<$name(IDname +"_"+ num).length; i++){
		$name(IDname +"_"+ num)[i].checked = CKD

		for (i2=0; i2<$name(IDname +"_"+ num +"_"+ i).length; i2++){
			$name(IDname +"_"+ num +"_"+ i)[i2].checked = CKD

			for (i3=0; i3<$name(IDname +"_"+ num +"_"+ i +"_"+ i2).length; i3++){
				$name(IDname +"_"+ num +"_"+ i +"_"+ i2)[i3].checked = CKD
			}

		}

	}

	CheckCheckBox(IDname)
}

//检测复选框
function CheckCheckBox(str){
	var CBcount=0
	var strTop=str.substring(0,str.lastIndexOf("_"))
	var strBottom=str.substring(str.lastIndexOf("_")+1,str.length)
	for (CBi=0; CBi<4; CBi++){
//		alert(strTop +"|"+ strBottom +"|"+ CBcount)
		CBcount=0
		if (strTop.length >= 6){
			for (i=0; i<$name(strTop +"_"+ strBottom).length; i++){
				if ($name(strTop +"_"+ strBottom)[i].checked == true){CBcount += 1}
			}
			if (CBcount == 0){
				$name(strTop)[strBottom].checked = false;
			}else{
				$name(strTop)[strBottom].checked = true;
			}
		}

		strBottom=strTop.substring(strTop.lastIndexOf("_")+1,strTop.length)
		strTop=strTop.substring(0,strTop.lastIndexOf("_"))
	}
}

//检测表单
function CheckRightForm(){
	var CFcount=0;CFstr="|"
	ULform.rightStr.value="";	//先清空
	for (i=0;i<ULform.elements.length;i++){
		if (ULform.elements[i].checked == true){
			CFcount += 1;
			CFstr += ULform.elements[i].value +"|";
		}
	}
	if (CFcount == 0){
		alert("不允许用户组无任何权限");return false;
	}else{
		ULform.rightStr.value = CFstr;
	}
}

//确定重置
function CheckReset(){
	if (confirm("您确定重置？") == false){return false}
}




//菜单列表隐藏、显示
function JudMenu(num){
	if (num == 2){ return ""; }else{ return "none"; }
}

//showMenu选中与否
function JudShowMenu(num){
	if (num == 2){ return "checked"; }else{ return ""; }
}



function CheckShowMenu(num){
	if ($name("selShowMenu")[num].checked == true){openSM=""}else{openSM="none"}
	if (num == 0){
		menuSM=BImenu.split(",")
		for (i=0; i<menuSM.length; i++){
			if (document.getElementById("menu"+ i).style.display != openSM){
				if (i+1 == menuSM.length){imgSM=2}else{imgSM=1}
				TurnMenu("menu"+ i,imgSM)
			}
		}
	}

	if (num == 1){
		menuSM=BImenu.split(",")
		for (i=0; i<menuSM.length; i++){
			menuSM2=eval("BImenu"+ i).split(",")
			for (i2=0; i2<menuSM2.length; i2++){
					try{
				if (document.getElementById("menu"+ i +"_"+ i2).style.display != openSM){
					if (i2+1 == menuSM2.length){imgSM=2}else{imgSM=1}
					TurnMenu("menu"+ i +"_"+ i2,imgSM)
				}
					}catch(e){}
			}
		}
	}
}



function WriteCode(){
	document.write(""+
	"<table border='0' cellSpacing='0' cellPadding='0'>"+
	"<tr><td colspan='2'><label><input type='checkbox' id='allRight' name='allRight' onclick='CheckBoxAll()' />所有权限</label></td></tr>");

	//主菜单
	BImenuSZ=BImenu.split(",");
	for (lv1=0; lv1<BImenuSZ.length; lv1++){
	if (lv1+1 == BImenuSZ.length){ judImgLv1=2; }else{ judImgLv1=1; }
	document.write(""+
	"<tr>"+
		"<td style='width:20px; height:26px;'>"+
			"<img id='menu"+ lv1 +"Img' src='images/userRight/dz"+ judImgLv1 +"_"+ judMenuLv1 +".gif' onclick=\"TurnMenu('menu"+ lv1 +"',"+ judImgLv1 +")\" />"+
		"</td>"+
		"<td>"+ ShowLevel(limitName,BImenuSZ[lv1],lv1) +"</td>"+
	"</tr>"+
	"<tr id='menu"+ lv1 +"' style='display:"+ JudMenu(judMenuLv1) +"'>"+
		"<td style=\"background:url('images/userRight/dz"+ (judImgLv1-1) +".gif');\"></td>"+
		"<td>")
			//菜单2
			errLv2="";
			try{ eval("BImenu"+ lv1); }catch (e){ errLv2="true"; }
			if (errLv2 != "true"){
			document.write(""+
			"<table border='0' cellSpacing='0' cellPadding='0'>");
			BImenu2SZ=eval("BImenu"+ lv1).split(",");
			for (lv2=0; lv2<BImenu2SZ.length; lv2++){
			if (lv2+1 == BImenu2SZ.length){judImgLv2=2}else{judImgLv2=1}
			document.write(""+
			"<tr>"+
				"<td style='width:20px; height:26px;'>")
					judChaImgLv2=""
					try{eval("BImenu"+ lv1 +"_"+ lv2)}catch (e){judChaImgLv2="true"}
					if (judChaImgLv2 == "true"){
						document.write(""+
						"<img src='images/userRight/dz"+ (judImgLv2+2) +".gif' alt='' />")
					}else{
						document.write(""+
						"<img id='menu"+ lv1 +"_"+ lv2 +"Img' src='images/userRight/dz"+ judImgLv2 +"_"+ judMenuLv2 +".gif' onclick=\"TurnMenu('menu"+ lv1 +"_"+ lv2 +"',"+ judImgLv2 +")\" alt='' />")
					}
				document.write(""+
				"</td>"+
				"<td>"+ ShowLevel(limitName +"_"+ lv1,BImenu2SZ[lv2],lv2) +"</td>"+
			"</tr>")
			if (judChaImgLv2 != "true"){	//判断是否显示start
			document.write(""+
			"<tr id='menu"+ lv1 +"_"+ lv2 +"' style='display:"+ JudMenu(judMenuLv2) +"'>"+
				"<td style=\"background:url('images/userRight/dz"+ (judImgLv2-1) +".gif');\"></td>"+
				"<td>")
					//菜单3
					errLv3=""
					try{eval("BImenu"+ lv1 +"_"+ lv2)}catch (e){errLv3="true"}
					if (errLv3 != "true"){
					document.write(""+
					"<table border='0' cellSpacing='0' cellPadding='0'>")
					BImenu3SZ=eval("BImenu"+ lv1 +"_"+ lv2).split(",")
					for (lv3=0; lv3<BImenu3SZ.length; lv3++){
					if (lv3+1 == BImenu3SZ.length){judImgLv3=2}else{judImgLv3=1}
					document.write(""+
					"<tr>"+
						"<td style='width:20px; height:26px;'>")
					judChaImgLv3=""
					try{eval("BImenu"+ lv1 +"_"+ lv2 +"_"+ lv3)}catch (e){judChaImgLv3="true"}
					if (judChaImgLv3 == "true"){
							document.write(""+
							"<img src='images/userRight/dz"+ (judImgLv3+2) +".gif' alt='' />")
					}else{
							document.write(""+
							"<img id='menu"+ lv1 +"_"+ lv2 +"_"+ lv3 +"Img' src='images/userRight/dz"+ judImgLv3 +"_"+ judMenuLv3 +".gif' onclick=\"TurnMenu('menu"+ lv1 +"_"+ lv2 +"_"+ lv3 +"',"+ judImgLv3 +")\" alt='' />")
					}
						document.write(""+
						"</td>"+
						"<td>"+ ShowLevel(limitName +"_"+ lv1 +"_"+ lv2,BImenu3SZ[lv3],lv3) +"</td>"+
					"</tr>")
					if (judChaImgLv3 != "true"){	//判断是否显示start
					document.write(""+
					"<tr id='menu"+ lv1 +"_"+ lv2 +"_"+ lv3 +"' style='display:"+ JudMenu(judMenuLv3) +"'>"+
						"<td style=\"background:url('images/userRight/dz"+ (judImgLv3-1) +".gif');\"></td>"+
						"<td>")
							//菜单4
							errLv4=""
							try{eval("BImenu"+ lv1 +"_"+ lv2 +"_"+ lv3)}catch (e){errLv4="true"}
							if (errLv4 != "true"){
							document.write(""+
							"<table border='0' cellSpacing='0' cellPadding='0'>")
							BImenu4SZ=eval("BImenu"+ lv1 +"_"+ lv2 +"_"+ lv3).split(",")
							//	alert(BImenu2SZ.length)
							for (lv4=0; lv4<BImenu4SZ.length; lv4++){
							if (lv4+1 == BImenu4SZ.length){judImgLv4=2}else{judImgLv4=1}
							document.write(""+
							"<tr>"+
								"<td style='width:20px; height:26px;'><img src='images/userRight/dz"+ (judImgLv4+2) +".gif' alt='' /></td>"+
								"<td>"+ ShowLevel(limitName +"_"+ lv1 +"_"+ lv2 +"_"+ lv3,BImenu4SZ[lv4],lv4) +"</td>"+
							"</tr>")
	//						document.write(""+
	//						"<tr id='menu"+ lv1 +"_"+ lv2 +"_"+ lv3 +"_"+ lv4 +"' style='display:"+ JudMenu(judMenuLv4) +"'>"+
	//							"<td style=\"background:url('images/userRight/dz"+ (judImgLv4-1) +".gif');\"></td>"+
	//							"<td>"+

	//							"</td>"+
	//						"</tr>")
							}
							document.write(""+
							"</table>")
							}
						document.write(""+
						"</td>"+
					"</tr>")
					}	//判断是否显示end
					}
					document.write(""+
					"</table>")
					}
				document.write(""+
				"</td>"+
			"</tr>")
			}
			}
			document.write(""+
			"</table>")
			}
	document.write(""+
		"</td>"+
	"</tr>")
	}
	document.write(""+
	"</table>")
}
